package com.dk.service.impl;

import com.dk.pojo.CarOrder;
import com.dk.mapper.CarOrderMapper;
import com.dk.service.CarOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 帅杰
 * @since 2021-08-11
 */
@Service
public class CarOrderServiceImpl extends ServiceImpl<CarOrderMapper, CarOrder> implements CarOrderService {

    @Autowired
    private CarOrderMapper carOrderMapper;

    //查询
    @Override
    public List<CarOrder> toSelect() {
        return carOrderMapper.selectList(null);
    }
    //新增
    @Override
    public void toInsert(CarOrder carOrder) {
        //将BigDecimal转换成toSpring在进行equals进行比较
        if (carOrder.getBond().toString().equals("5000")){
            carOrder.setStatus("1");
            //BigDecimal类型比较数字大小 转换成int
        }else if (carOrder.getBond().intValue()>5000){
            carOrder.setStatus("2");
        }else {
            carOrder.setStatus("3");
        }

        carOrderMapper.insert(carOrder);
    }
    //修改
    @Override
    public void toUpdate(CarOrder carOrder) {
       carOrderMapper.updateById(carOrder);
    }

    //删除
    @Override
    public boolean toDelete(Long orderId) {
        CarOrder carOrder=new CarOrder();
        carOrder.setCustomerId(orderId);
        carOrder.setStatus("4");
        int i = carOrderMapper.updateById(carOrder);
        return i>0;
    }
}
